package fr.emse.tatiana.replayable;

import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IPersistableElement;

import fr.emse.tatiana.replayable.analysis.IAnalysis;

public class CreatedReplayableInput implements IReplayableInput {

	protected static int ID = 0;

	protected IAnalysis model;
	protected IFile file;
	protected IProject p;

	public CreatedReplayableInput(IProject p) {
		this.p=p;
	}

	public CreatedReplayableInput(IFile file) {
		this.file=file;
		this.p = file.getProject();
	}

	public void init() {
		// do nothing
	}

	public boolean exists() {
		return file.exists();
	}

	public ImageDescriptor getImageDescriptor() {
		return null;
	}

	public String getName() {
		try {
			return getFile().getName();
		} catch (Exception e) {
			return "Untitled";
		}
	}

	public IPersistableElement getPersistable() {
		// TODO z later when persistence is implemented
		return null;
	}

	public String getToolTipText() {
		return getName();
	}

	public Object getAdapter(Class adapter) {
		return null;
	}

	private IFile getFile() {
		return this.file;
	}

	public IProject getProject() {
		return this.p;
	}

	public IReplayableModel getDisplayModel(List<IAnalysis> analyses) {
		IFile file = getFile();
		if (file == null) {
			return new ReplayableModel(getProject(), analyses);
		} else {
			return ReplayableModelFactory.getEditableReplayableModel(file, analyses);
		}
	}


}
